package cn.jobstart.es.service.impl;

import cn.jobstart.common.*;
import cn.jobstart.es.listener.event.*;
import cn.jobstart.es.mapper.ResumeEsMapper;
import cn.jobstart.es.model.ResumeEs;
import cn.jobstart.es.search.ResumeEsSearch;
import cn.jobstart.es.service.AbstractEsService;
import cn.jobstart.es.service.IResumeEsService;
import cn.jobstart.es.vo.ResumeEsMatching;
import cn.jobstart.es.vo.ResumeEsVO;
import cn.jobstart.model.ResumeBasic;
import cn.jobstart.modelExt.*;
import cn.jobstart.pubInter.exception.SkException;
import cn.jobstart.service.*;
import cn.jobstart.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author sunke
 * @version 1.0
 * @Description
 * @date 2023-09-06 21:38
 */
@Service
@Slf4j
public class ResumeEsServiceImpl extends AbstractEsService<ResumeEs, ResumeEsSearch, ResumeEsMapper> implements IResumeEsService {


    @Resource
    private ResumeEsMapper resumeEsMapper;
    @Resource
    private IAdminJobCandidateService adminJobCandidateService;
    @Resource
    private IAdminJobService adminJobService;

    @Resource
    private IResumeBasicService resumeBasicService;
    @Resource
    private IResumeAssociationActivityService resumeAssociationActivityService;
    @Resource
    private IResumeCapabilityLabelService resumeCapabilityLabelService;
    @Resource
    private IResumeCertificateService resumeCertificateService;
    @Resource
    private IResumeEducationalExperienceService resumeEducationalExperienceService;
    @Resource
    private IResumeEmploymentIntentionService resumeEmploymentIntentionService;
    @Resource
    private IResumeProjectExperienceService resumeProjectExperienceService;
    @Resource
    private IResumeWorkExperienceService resumeWorkExperienceService;

    @Resource
    private ITalentSubscriptionTaskService talentSubscriptionTaskService;

    @Override
    public ResumeEsMapper getMapper() {
        return resumeEsMapper;
    }


    /**
     * 根据第三方ID 查询
     *
     * @param thirdAccountId
     * @return
     */
    @Override
    public ResumeEs getDetailByThirdAccountId(String thirdAccountId) {
        try {
            if (StringUtil.isNullOrEmpty(thirdAccountId)) {
                return null;
            }
            ResumeEsSearch esSearch = ResumeEsSearch.getInstance();
            esSearch.setThirdAccountIdEq(thirdAccountId);
            esSearch.setPageNumber(1);
            esSearch.setPageSize(1);

            List<ResumeEs> esList = selectList(esSearch);
            if (StringUtil.isNullOrEmpty(esList)) {
                return null;
            }

            return esList.get(0);
        } catch (Exception e) {
            return null;
        }
    }




    /**
     * 入到数据库
     *
     * @param vo
     */
    @Override
    public void insertAll(ResumeEsMatching vo) {

        try {
            ResumeEsVO resumeEsVO = matchingOne(vo);

            String personId = null;

            //说明没有匹配上
            if (StringUtil.isNullOrEmpty(resumeEsVO) || resumeEsVO.getMatchingVector() < 4) {
                return;
            }

            //爬取过来的年龄
            int thirdAge=vo.getThirdAge();

            //匹配出来的年龄
            int age=NumberUtil.parseInt(resumeEsVO.getAge(),-1);



            //说明设置年龄
            if(age!=-1 && thirdAge!=-1){
               // 年龄正负3岁
                if(Math.abs(age-thirdAge)>3){
                    return;
                }
            }

            personId = resumeEsVO.getPersonId();
            vo.setPersonId(personId);
            String taskId=vo.getTalentSubscriptionTaskId();
            String thirdAccountId = vo.getThirdAccountId();

            ResumeEs oldResumeEs = getDetailByThirdAccountId(thirdAccountId);
            ResumeBasicExt resumeBasic = null;
            //说明原来就有这个人简历  就直接更新
            if (StringUtil.isNotObjEmpty(oldResumeEs)) {

                String resumeBasicId = oldResumeEs.getId();

                oldResumeEs.setResumeModifyTime(new Date());
              /*  if(StringUtil.isNotObjEmpty(taskId)) {
                    oldResumeEs.setTalentSubscriptionTaskId(taskId);
                }*/
                update(oldResumeEs, resumeBasicId);



                //更新简历更新时间
                resumeBasicService.updateDataById(SkMap.getInstance().addObjToMap(ResumeBasic.RESUME_MODIFY_TIME, new Date()), resumeBasicId);


                talentSubscriptionTaskService.updateResumeUpdateCountByTaskIdAndCount(vo.getTalentSubscriptionTaskId(), 1);


                return;

            }


           /* //说明匹配上，
            if (StringUtil.isNotObjEmpty(resumeEsVO) && resumeEsVO.getMatchingVector() >= 4) {
                personId = resumeEsVO.getPersonId();
                vo.setPersonId(personId);
            }*/


            resumeBasic = new ResumeBasicExt();
            BeanUtils.copyPropertiesIgnoreNull(vo, resumeBasic);
            resumeBasic.setKzpStudentId(thirdAccountId);


            resumeBasic = resumeBasicService.insert(resumeBasic);


            //在校经历
            addSchoolJob(vo, resumeBasic);
            //能力
            addCapabilityLabel(vo, resumeBasic);
            //证书
            addCertificate(vo, resumeBasic);
            //添加教育
            addEducationalExperience(vo, resumeBasic);

            //添加求职意向
            addEmploymentIntention(vo, resumeBasic);
            //添加项目经历
            addProjectExperience(vo, resumeBasic);
            //添加工作经历
            addWorkExperience(vo, resumeBasic);


            publishCompleteByResumeId(resumeBasic.getId());


        } catch (SkException e) {
            e.printStackTrace();
        }


    }

    /**
     * 添加工作经历
     *
     * @param vo
     * @param resumeBasic
     */
    private void addWorkExperience(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeWorkExperienceMiniDomainVO> workExperienceList = vo.getWorkExperienceList();
            if (StringUtil.isNullOrEmpty(workExperienceList)) {
                return;
            }
            workExperienceList.stream().forEach(item -> {

                try {
                    ResumeWorkExperienceExt itemModel = new ResumeWorkExperienceExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);


                    resumeWorkExperienceService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }

    /**
     * 添加项目经历
     *
     * @param vo
     * @param resumeBasic
     */
    private void addProjectExperience(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeProjectExperienceMiniDomainVO> projectExperienceList = vo.getProjectExperienceList();
            if (StringUtil.isNullOrEmpty(projectExperienceList)) {
                return;
            }
            projectExperienceList.stream().forEach(item -> {

                try {
                    ResumeProjectExperienceExt itemModel = new ResumeProjectExperienceExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);


                    resumeProjectExperienceService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }

    /**
     * 添加求职意向
     *
     * @param vo
     * @param resumeBasic
     */
    private void addEmploymentIntention(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeEmploymentIntentionMiniDomainVO> employmentIntentionList = vo.getEmploymentIntentionList();
            if (StringUtil.isNullOrEmpty(employmentIntentionList)) {
                return;
            }
            employmentIntentionList.stream().forEach(item -> {

                try {
                    ResumeEmploymentIntentionExt itemModel = new ResumeEmploymentIntentionExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);


                    resumeEmploymentIntentionService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }

    /**
     * 添加教育
     *
     * @param vo
     * @param resumeBasic
     */
    private void addEducationalExperience(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeEducationalExperienceMiniDomainVO> educationalExperienceList = vo.getEducationalExperienceList();
            if (StringUtil.isNullOrEmpty(educationalExperienceList)) {
                return;
            }
            educationalExperienceList.stream().forEach(item -> {

                try {
                    ResumeEducationalExperienceExt itemModel = new ResumeEducationalExperienceExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);


                    resumeEducationalExperienceService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }

    /**
     * 添加证书
     *
     * @param vo
     * @param resumeBasic
     */
    private void addCertificate(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeCertificateMiniDomainVO> certificateList = vo.getCertificateList();
            if (StringUtil.isNullOrEmpty(certificateList)) {
                return;
            }
            certificateList.stream().forEach(item -> {

                try {
                    ResumeCertificateExt itemModel = new ResumeCertificateExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);

                    resumeCertificateService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }

    /**
     * 添加能力
     *
     * @param vo
     * @param resumeBasic
     */
    private void addCapabilityLabel(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeCapabilityLabelMiniDomainVO> capabilityLabelList = vo.getCapabilityLabelList();
            if (StringUtil.isNullOrEmpty(capabilityLabelList)) {
                return;
            }
            capabilityLabelList.stream().forEach(item -> {

                try {
                    ResumeCapabilityLabelExt itemModel = new ResumeCapabilityLabelExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);

                    resumeCapabilityLabelService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }

    /**
     * 添加在校经历
     *
     * @param vo
     * @param resumeBasic
     */
    private void addSchoolJob(ResumeEsMatching vo, ResumeBasicExt resumeBasic) {
        try {
            if (StringUtil.isNullOrEmpty(vo) || StringUtil.isNullOrEmpty(resumeBasic)) {
                return;
            }
            String resumeId = resumeBasic.getId();
            List<ResumeAssociationActivityMiniDomainVO> associationActivityList = vo.getAssociationActivityList();
            if (StringUtil.isNullOrEmpty(associationActivityList)) {
                return;
            }
            associationActivityList.stream().forEach(item -> {

                try {
                    ResumeAssociationActivityExt itemModel = new ResumeAssociationActivityExt();
                    BeanUtils.copyPropertiesIgnoreNull(item, itemModel);

                    itemModel.setResumesId(resumeId);

                    resumeAssociationActivityService.insert(itemModel);
                } catch (SkException e) {
                    e.printStackTrace();
                }


            });


        } catch (Exception e) {

        }


    }


    private ResumeEsSearch initSearch(ResumeEsVO vo) {
        ResumeEsSearch esSearch = ResumeEsSearch.getInstance();
        String truename = "";
        if (StringUtil.isNullOrEmpty(vo.getTruename()) || StringUtil.isNullOrEmpty(vo.getSexFlag())) {
            return null;
        }
        if (StringUtil.isNotObjEmpty(vo.getTruename())) {
            truename = vo.getTruename().substring(0, 1);
        }
        esSearch.setTruenameRightLike(truename);
        esSearch.setSexIn(SkList.getInstance().addObjToList(vo.getSexFlag()));
        esSearch.setTalentSubscriptionTaskIdEmptyFlag(1);//要匹配非订阅过来的数据
        return esSearch;

    }


    /**
     * 匹配学校
     *
     * @param allMap
     * @param vo
     */
    private void matchingSchool(Map<String, ResumeEsVO> allMap, ResumeEsMatching vo) {

        ResumeEsSearch esSearch = initSearch(vo);
        if (StringUtil.isNullOrEmpty(esSearch)) {
            return;
        }
        //教育经历
        List<ResumeEducationalExperienceMiniDomainVO> educationList = vo.getEducationalExperienceList();
        if (StringUtil.isNullOrEmpty(educationList)) {
            return;
        }
        //当前要匹配数据的教育经历，
        for (ResumeEducationalExperienceMiniDomainVO eduVo : educationList) {
            try {
                //毕业学校
                String schoolName = eduVo.getTitle();
                if (StringUtil.isNullOrEmpty(schoolName)) {
                    continue;
                }
                //教育开始时间
                Date startTime = eduVo.getStartTime();
                //教育结束时间
                Date endTime = eduVo.getEndTime();

                esSearch.setEducationalExperienceLike(schoolName);
                List<ResumeEs> resultList = selectList(esSearch);
                if (StringUtil.isNullOrEmpty(resultList)) {
                    continue;
                }
                //找到所有学校相关的数据
                resultList.stream().forEach(item -> {

                    //说明没有匹配到
                    if (StringUtil.isNullOrEmpty(item.getEducationalExperience()) || item.getEducationalExperience().indexOf(schoolName) == -1) {
                        return;
                    }
                    ResumeEsVO resumeEsVO = ResumeEsVO.getInstance();
                    BeanUtils.copyPropertiesIgnoreNull(item, resumeEsVO);

                    //添加匹配数量
                    addMatchingVector(allMap, item.getId(), resumeEsVO);

                    //当前匹配的教育经历
                    List<ResumeEducationalExperienceMiniDomainVO> findEsList = resumeEsVO.getEducationalExperienceList();
                    if (StringUtil.isNullOrEmpty(findEsList)) {
                        return;
                    }
                    if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
                        return;
                    }

                    //说明找到学校，然后匹配时间
                    for (ResumeEducationalExperienceMiniDomainVO eduItem : findEsList) {
                        if ((StringUtil.isNotObjEmpty(eduItem.getTitle()) && eduItem.getTitle().indexOf(schoolName) >= 0) || (StringUtil.isNotObjEmpty(eduItem.getDetail()) && eduItem.getDetail().indexOf(schoolName) >= 0)

                        ) {
                            if (YXDate.containLap(startTime, endTime, eduItem.getStartTime(), eduItem.getEndTime())) {
                                addMatchingVector(allMap, item.getId(), resumeEsVO);
                                break;
                            }
                        }
                    }


                });
            } catch (SkException e) {
                // e.printStackTrace();
            }

        }

    }

    /**
     * 匹配专业
     *
     * @param allMap
     * @param vo
     */
    private void matchingMajor(Map<String, ResumeEsVO> allMap, ResumeEsMatching vo) {
        ResumeEsSearch esSearch = initSearch(vo);
        if (StringUtil.isNullOrEmpty(esSearch)) {
            return;
        }
        //教育经历
        List<ResumeEducationalExperienceMiniDomainVO> educationList = vo.getEducationalExperienceList();
        if (StringUtil.isNullOrEmpty(educationList)) {
            return;
        }
        //当有要匹配的数据
        for (ResumeEducationalExperienceMiniDomainVO eduVo : educationList) {
            try {
                //专业
                String major = eduVo.getUnitName();
                if (StringUtil.isNullOrEmpty(major)) {
                    continue;
                }
                esSearch.setEducationalExperienceLike(major);
                List<ResumeEs> resultList = selectList(esSearch);
                if (StringUtil.isNullOrEmpty(resultList)) {
                    continue;
                }

                resultList.stream().forEach(item -> {
                    if (StringUtil.isNotObjEmpty(item.getEducationalExperience()) && item.getEducationalExperience().indexOf(major) >= 0) {
                        ResumeEsVO resumeEsVO = ResumeEsVO.getInstance();
                        BeanUtils.copyPropertiesIgnoreNull(item, resumeEsVO);
                        addMatchingVector(allMap, item.getId(), resumeEsVO);
                    }
                });

            } catch (SkException e) {

            }

        }


    }

    /**
     * 添加匹配数量
     *
     * @param allMap
     * @param id
     * @param resumeEsVO
     */
    private void addMatchingVector(Map<String, ResumeEsVO> allMap, String id, ResumeEsVO resumeEsVO) {
        //说明原来就有，
        if (allMap.containsKey(id)) {
            resumeEsVO.setMatchingVector(allMap.get(id).getMatchingVector() + 1);
        } else {
            resumeEsVO.setMatchingVector(1);
        }
        allMap.put(id, resumeEsVO);
    }

    /**
     * 匹配工作经历
     *
     * @param allMap
     * @param vo
     */
    private void matchingWork(Map<String, ResumeEsVO> allMap, ResumeEsMatching vo) {
        ResumeEsSearch esSearch = initSearch(vo);
        if (StringUtil.isNullOrEmpty(esSearch)) {
            return;
        }
        //要匹配工作经历
        List<ResumeWorkExperienceMiniDomainVO> workList = vo.getWorkExperienceList();
        if (StringUtil.isNullOrEmpty(workList)) {
            return;
        }
        for (ResumeWorkExperienceMiniDomainVO workVo : workList) {
            try {
                //公司
                String company = workVo.getUnitName();
                Date startTime = workVo.getStartTime();
                Date endTime = workVo.getEndTime();
                if (StringUtil.isNullOrEmpty(company)) {
                    continue;
                }
                esSearch.setWorkCompanyLike(company);
                List<ResumeEs> resultList = selectList(esSearch);
                if (StringUtil.isNullOrEmpty(resultList)) {
                    continue;
                }
                resultList.stream().forEach(item -> {
                    //说明没有匹配到
                    if (StringUtil.isNullOrEmpty(item.getWorkExperience()) || item.getWorkExperience().indexOf(company) == -1) {
                        return;
                    }

                    ResumeEsVO resumeEsVO = ResumeEsVO.getInstance();
                    BeanUtils.copyPropertiesIgnoreNull(item, resumeEsVO);
                    //说明匹配上了公司
                    addMatchingVector(allMap, item.getId(), resumeEsVO);


                    if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
                        return;
                    }
                    //当前匹配es查询的的工作经历
                    List<ResumeWorkExperienceMiniDomainVO> findEsList = resumeEsVO.getWorkExperienceList();
                    if (StringUtil.isNullOrEmpty(findEsList)) {
                        return;
                    }

                    //去匹配公司名称，详情，内容 有没有这个公司，再去匹配时间
                    for (ResumeWorkExperienceMiniDomainVO eduItem : findEsList) {
                        if ((StringUtil.isNotObjEmpty(eduItem.getUnitName()) && eduItem.getUnitName().indexOf(company) >= 0) || (StringUtil.isNotObjEmpty(eduItem.getContent()) && eduItem.getContent().indexOf(company) >= 0) || (StringUtil.isNotObjEmpty(eduItem.getDetail()) && eduItem.getDetail().indexOf(company) >= 0)) {
                            if (YXDate.containLap(startTime, endTime, eduItem.getStartTime(), eduItem.getEndTime())) {
                                addMatchingVector(allMap, item.getId(), resumeEsVO);
                                break;
                            }
                        }
                    }
                });
            } catch (SkException e) {

            }
        }
    }


    /**
     * 匹配得到
     *
     * @param vo
     * @return
     */
    @Override
    public Map<String, ResumeEsVO> matching(ResumeEsMatching vo) {
        if (StringUtil.isNullOrEmpty(vo)) {
            return null;
        }
        Map<String, ResumeEsVO> allMap = SkMap.getInstance();

        //匹配学校
        matchingSchool(allMap, vo);
        //匹配专业
        matchingMajor(allMap, vo);
        //匹配工作单位
        matchingWork(allMap, vo);



        return sortByValueDescending(allMap);


    }

    @Override
    public ResumeEsVO matchingOne(ResumeEsMatching vo) {
        Map<String, ResumeEsVO> dataMap = matching(vo);
        if (StringUtil.isNullOrEmpty(dataMap)) {
            return null;
        }
        // 获取第一个元素的键和值
        Optional<Map.Entry<String, ResumeEsVO>> firstEntry = dataMap.entrySet().stream().findFirst();

        if (firstEntry.isPresent()) {
            Map.Entry<String, ResumeEsVO> entry = firstEntry.get();
            return entry.getValue();
        }

        return null;
    }

    //降序排序
    private Map<String, ResumeEsVO> sortByValueDescending(Map<String, ResumeEsVO> map) {
        if (StringUtil.isNullOrEmpty(map)) {
            return map;
        }

        List<Map.Entry<String, ResumeEsVO>> list = new LinkedList<Map.Entry<String, ResumeEsVO>>(map.entrySet());

        Collections.sort(list, new Comparator<Map.Entry<String, ResumeEsVO>>() {
            @Override
            public int compare(Map.Entry<String, ResumeEsVO> o1, Map.Entry<String, ResumeEsVO> o2) {

                return o2.getValue().getMatchingVector() - o1.getValue().getMatchingVector();

            }
        });

        Map<String, ResumeEsVO> result = new LinkedHashMap<String, ResumeEsVO>();
        for (Map.Entry<String, ResumeEsVO> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }
        return result;

    }


    /**
     * 发布到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishByResumeId(String resumeId) throws SkException {
        ResumeEsEvent event = new ResumeBaseAddEvent();
        event.setResumeId(resumeId);
        publishEvent(event);

    }

    /**
     * 发布完整的
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishCompleteByResumeId(String resumeId) throws SkException {

        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeBaseEsAddAllEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    /**
     * 在校经历
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishAssociationActivityByResumeId(String resumeId) throws SkException {
        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeAssociationActivityEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);

    }

    /**
     * 发布简历能力标签
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeCapabilityLabelByResumeId(String resumeId) throws SkException {

        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }

        ResumeEsEvent event = new ResumeCapabilityLabelEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);


    }

    /**
     * 发布证书到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeCertificateByResumeId(String resumeId) throws SkException {
        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }

        ResumeEsEvent event = new ResumeCertificateEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);

    }

    /**
     * 发布教育经历到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeEducationalExperienceByResumeId(String resumeId) throws SkException {
        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeEducationalExperienceUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    /**
     * 发布求职意向到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeEmploymentIntentionByResumeId(String resumeId) throws SkException {
        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeEmploymentIntentionUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    /**
     * 发布实习经历到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeIntershipByResumeId(String resumeId) throws SkException {
        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeIntershipEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    /**
     * 发布专业技能到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeProfessionalSkillsByResumeId(String resumeId) throws SkException {

        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeProfessionalSkillsEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    /**
     * 发布项目经历到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeProjectExperienceByResumeId(String resumeId) throws SkException {

        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeProjectExperienceEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);

    }

    /**
     * 发布培训经历到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeTrainingExperienceByResumeId(String resumeId) throws SkException {

        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeTrainingExperienceEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    /**
     * 发布工作经历到es
     *
     * @param resumeId
     * @throws SkException
     */
    @Override
    public void publishResumeWorkExperienceByResumeId(String resumeId) throws SkException {
        if (StringUtil.isNullOrEmpty(resumeId)) {
            return;
        }
        ResumeEsEvent event = new ResumeWorkExperienceEsUpdateEvent();
        event.setResumeId(resumeId);
        publishEvent(event);
    }

    @Override
    public void beforePageQuery(ResumeEsSearch resumeEsSearch, int pageNum, int pageSize) throws SkException {
        super.beforePageQuery(resumeEsSearch, pageNum, pageSize);

        //说明有传员工职位ID 就把相关的候选人匹配的简历排外
        if (StringUtil.isNotObjEmpty(resumeEsSearch.getAdminJobIdEq())) {
            List<String> resumeIds = adminJobCandidateService.getResumeIdsByAdminJobId(resumeEsSearch.getAdminJobIdEq());
            if (StringUtil.isNotObjEmpty(resumeIds)) {
                resumeEsSearch.not().in(ResumeEs::getId, resumeIds);
            }

            //临时用一下
            if (StringUtil.isNullOrEmpty(resumeEsSearch.getKeywordLike())) {

                try {
                    AdminJobExt adminJob = adminJobService.getDetail(resumeEsSearch.getAdminJobIdEq());
                    resumeEsSearch.setKeywordLike(adminJob.getTitle());
                } catch (Exception e) {

                }


            }

        }

    }


}
